perm filename A67.TEX[106,RWF] blob
sn#807762 filedate 1985-09-20 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00005 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \magnification\magstephalf
C00023 00003 \noindent
C00050 00004 \noindent
C00054 00005 \noindent
C00062 ENDMK
C⊗;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a67.tex[106,phy] \today\hfill}
%\def\return{$\swarrow$}
\def\return{\mskip1mu\raise2pt\vbox{\hbox{$\scriptstyle\rm c$}}
\hbox{$\scriptstyle\rm r$}}
%\def\esc{\mskip1mu\raise2pt\vbox{\hbox{$\scriptstyle\rm c$}}
%\hbox{$\scriptstyle\rm t$}}
\def\esc{\mskip1mu\raise2pt\vbox{\hbox{$\scriptstyle\rm e$}}
\raise1pt\vbox{\hbox{$\scriptstyle\rm s$}}
\hbox{$\scriptstyle\rm c$}\mskip1mu}
\bigskip
\noindent
{\bf APPENDIX B.} File Protection.
%\sendindex{File Protection}
Unless you take some action to protect your files, they can be read or
copied by anyone. This is inapropriate for course assignments, in a world
where not everyone is honest. To change the protection status of a file,
use the TOPS-20 command
\smallskip\halign{\qquad\lft{\tt #}\cr
@\undertext{SET FILE PROTECTION {\sl filename n}}\cr}
\smallskip
\noindent
where $n$ is a six digit number, say {\tt AABBCC}. Here the two
digits~{\tt AA}
control what you yourself can do to the file, {\tt BB}~control what members of
your ``group'' can do (meaningless for courses),
and CC controls what everyone else can do to your file.
Each of these two digit numbers is obtained by adding up codes for the
capabilities you want to allow, according to this code:
\display 40pt:
40:Allow reading.
\display 40pt:
20:Allow writing (i.e., changing the file, possibly
\display 40pt::
losing its current contents).
\display 40pt:
10:Allow executing.
\display 40pt:
04:Allow appending to the file.
\display 40pt:
02:Allow appearance in directory listings.
\display 40pt:
01:Has no effect.
\smallskip
If you don't protect a file, it has protection number 777752,
so anyone can read or execute it or see that it is
in your directory; only you can change or add to it. A more appropriate
protection number for homework Pascal programs is 777702.
You may at times want to protect your files even from yourself, to prevent
unintentional erasing.
You can set the protection for all files you create in the future by
the TOPS-20 command
\smallskip\halign{\qquad\lft{\tt #}\cr
@\undertext{SET DIRECTORY FILE-PROTECTION-DEFAULT {\sl username n}}\cr}
\smallskip
\noindent
where $n$ is again the protection number. This command does not affect
present
or future generations of existing files. It does not prevent you from changing
the protection numbers on individual files after creating them.
For more details, see {\sl LOTS DEC System-20 Overview}, section 2.5.2.1
\vfill\eject
\noindent
{\bf APPENDIX C.} More TOPS-20 Commands.
%\sendindex{More TOPS-20 Commands}
How to do some common tasks in file handling at LOTS.
\vskip 14pt
\outlineone $\bullet$:
Getting information about the system.
\outlinetwo $\Rightarrow$:
Information about a TOPS-20 command:
\outlinetwo :
@\undertext{\tt HELP {\sl command-name} $\return$}
\outlinetwo $\Rightarrow$:
Information about what you can type next:
\outlinetwo :
\undertext{$\esc$}
\outlinetwo :
or
\outlinetwo :
\undertext{?}
\outlinetwo $\Rightarrow$:
Information about files.
\outlinethree $\Rightarrow$:
To see what files you have (names only):
\outlinethree :
@\undertext{\tt DIRECTORY $\return$}
\outlinethree $\Rightarrow$:
To see more detailed information about those files (protection status,
pages, size, date):
\outlinetwo :
@\undertext{\tt VD $\return$}
\outlinethree :
(stands for ``verbose directory'')
\outlinethree $\Rightarrow$:
To see such information about a subset of your directory, or about
another directory:
\outlinetwo :
@\undertext{\tt DIRECTORY $\esc$ {\sl files} $\return$}
\outlinethree :
(similar for VD)
\outlinethree $\Rightarrow$:
To see which files have been deleted but not yet expunged:
\outlinetwo :
@\undertext{\tt QDIRECTORY $\return$}
\outlinethree $\Rightarrow$:
To see general information about a directory:
\outlinetwo :
@\undertext{\tt INFO
$\esc$ DIRECTORY $\esc$ {} $\langle${\sl directory name\/}$\rangle$
{} $\return$}
\outlinethree :
or, for more detail,
\outlinetwo :
@\undertext{\tt INFO
$\esc$ DIRECTORY $\esc$ {\sl $\langle$directory name\/}$\rangle$,
$\return$}
\outlinetwo :
@@\undertext{\tt VERBOSE $\return$}
\outlinetwo :
@@\undertext{$\return$}
\outlinetwo $\Rightarrow$:
Information about the system, and your program, if you have one running:
\outlinetwo :
\undertext{CTRL/T}
\outlinetwo $\Rightarrow$:
Information about what files are waiting to be printed (yours and
others'), showing job names, sequence numbers, sizes, and user names:
\outlinetwo :
@\undertext{\tt INFORMATION $\esc$ OUTPUT-REQUESTS $\return$}
\outlinetwo $\Rightarrow$:
Information about the current time and date:
\outlinetwo :
@\undertext{\tt DAYTIME $\return$}
\outlinetwo $\Rightarrow$:
Information about your terminal time allocation:
\outlinetwo :
@\undertext{\tt INFORMATION $\esc$ ALLOCATION $\return$}
\outlineone $\bullet$:
Making permanent changes in the system conventions for handling
your files and jobs:
\outlinetwo :
@\undertext{\tt SET \dots}
\outlineone :
is used for most such changes.
\vfill\eject
\outlineone :
Some important cases of SET follow. To see what conventions are
in effect for you, use the INFO commands.
%\sendnotes{RWF-In your notes you wrote "Checkout??????==>" the section To }
%\sendnotes{change the number of generations kept in your files:}
\outlinetwo $\Rightarrow$:
To change the number of generations kept in your files:
\outlinetwo :
@\undertext{\tt SET $\esc$ DIRECTORY $\esc$ GENERATION $\esc$
{\sl directory-name $\esc$ number\/} $\return$}
\outlinetwo :
{\tt PASSWORD:}\undertext{\tt Your password $\return$}
\outlinetwo $\Rightarrow$:
To change the level of protection of directory information:
\outlinetwo :
@\undertext{\tt SET $\esc$ DIRECTORY $\esc$ PROTECTION $\esc$
{\sl directory-name $\esc$ number\/} $\return$}
\outlinetwo :
{\tt PASSWORD:}\undertext{\tt Your password $\return$}
\outlinetwo $\Rightarrow$:
To change the level of protection automatically given to files you create
in the future:
\outlinetwo :
@\undertext{\tt SET $\esc$ DIRECTORY $\esc$ FILE-PROTECTION-DEFAULT $\esc$
{\sl directory-name\/} $\esc$}
\outlinetwo :
\undertext{{\sl number\/} $\return$}
\outlinetwo $\Rightarrow$:
See also printing format defaults, and initialization files.
\outlineone $\bullet$:
Correcting mistakes.
\outlinetwo $\Rightarrow$:
To cancel a printing request:
\outlinetwo :
@\undertext{\tt CANCEL $\esc$ PRINT $\esc$ {\sl jobname\/} $\return$}
\outlinetwo :
or
\outlinetwo :
@\undertext{\tt CANCEL $\esc$ PRINT $\esc$ /SEQ $\esc$ {\sl sequence number\/}
$\return$}
\outlinetwo $\Rightarrow$:
To cancel all your current print requests:
\outlinetwo :
@\undertext{\tt CANCEL $\esc$ PRINT $\esc$ {\tt *} $\return$}
\outlinetwo $\Rightarrow$:
To retrieve deleted files:
\outlinetwo :
@\undertext{\tt UNDELETE $\esc$ {\sl files\/} $\return$}
\outlinetwo :
(use generation number)
\outlinetwo $\Rightarrow$:
To change switch settings on a pending print request:
%\sendnotes{FINALCHECK - see if help modify looks right.}
\outlinetwo :
@\undertext{\tt MODIFY $\esc$ PRINT $\esc$ \dots} (see
@\undertext{\tt HELP $\esc$ MODIFY $\return$} or
@\undertext{\tt HELP $\esc$ PRINT $\return$})
\outlinetwo $\Rightarrow$:
To make a printed record of everything that appears on your
terminal for some period of time (useful to show to consultants later for
diagnostic help):
\outlinetwo :
@\undertext{\tt PHOTO $\return$} (see
@\undertext{\tt HELP $\esc$ PHOTO $\return$})
\outlineone $\bullet$:
Sending messages.
\outlinetwo $\Rightarrow$:
To send mail to another user.
\outlinetwo :
@\undertext{\tt MAIL {\sl username\/} $\return$}
\outlinetwo :
{\tt SUBJECT}:\undertext{\tt one line title $\return$}
\outlinetwo :
{\tt MESSAGE}:\undertext{\tt as many lines as you like}
\outlinetwo :
\undertext{\tt terminated with CTRL/Z.}
\outlinetwo :
You can also send mail to or from files --- see
@\undertext{\tt HELP $\esc$ MAIL $\return$}
\outlinetwo $\Rightarrow$:
To read your mail:
\outlinetwo :
@\undertext{\tt TYPE MAIL.TXT $\return$}
\outlinetwo $\Rightarrow$:
To delete all mail:
\outlinetwo :
@\undertext{\tt DELETE MAIL.TXT $\return$}
\outlinetwo $\Rightarrow$:
To delete part of your mail (and for general information about mail):
\outlinetwo :
@\undertext{\tt HELP MM $\return$}
\vfill\eject
\outlinetwo $\Rightarrow$:
To send a message to someone at another terminal:
\outlinetwo :
@\undertext{\tt SEND $\esc$ username $\esc$ one-line-message $\return$}
\outlinetwo :
To send a long message:
\outlinetwo :
@\undertext{\tt NSEND $\return$}
\outlinetwo :
or
\outlinetwo :
@\undertext{\tt HELP NSEND $\return$}
\outlineone $\bullet$:
Printing.
\outlinetwo $\Rightarrow$:
To limit printing to $n$ pages:
\outlinetwo :
@\undertext{\tt PRINT $\esc$ files $\esc$ /LIMIT: n $\return$}
\outlinetwo $\Rightarrow$:
To insert a note, up to 12 characters, in output header:
\outlinetwo :
@\undertext{\tt PRINT $\esc$ files $\esc$ /NOTE: text of note $\return$}
\outlinetwo $\Rightarrow$:
To print some files at a specified later time (e.g., late at night):
\outlinetwo :
@\undertext{\tt PRINT $\esc$ files $\esc$ /AFTER: \dots}
%\sendnotes{==>RWF-can't put all on one line because of macro}
\outlinetwo :
(see @\undertext{\tt HELP $\esc$ PRINT $\return$}
\outlinetwo $\Rightarrow$:
To print and then delete a file:
\outlinetwo :
@\undertext{\tt PRINT $\esc$ files $\esc$ /DELETE $\return$}
\outlinetwo $\Rightarrow$:
To print binary files, in octal:
\outlinetwo :
@\undertext{\tt PRINT $\esc$ files $\esc$ /PRINT: OCTAL $\return$}
%\sendnotes{How to print suppressing control characters?Check at LOTS}
\outlinetwo $\Rightarrow$:
To print double or triple-spaced:
\outlinetwo :
@\undertext{\tt PRINT $\esc$ files $\esc$ /SPACING: DOUBLE $\return$}
\outlinetwo :
@\undertext{\tt PRINT $\esc$ files $\esc$ /SPACING: TRIPLE $\return$}
\outlinetwo $\Rightarrow$:
To automatically include the above switches, like {\tt /LIMIT: n}, in your
print commands:
\outlinetwo :
@\undertext{\tt SET $\esc$ DEFAULT $\esc$ PRINT $\esc$ /switch $\return$}
\outlinetwo $\Rightarrow$:
To clear all such automatic switches:
\outlinetwo :
@\undertext{\tt SET $\esc$ NO $\esc$ DEFAULT $\esc$ PRINT $\return$}
\outlineone $\bullet$:
Handling programs.
\outlineone :
({\tt COMPILE}, {\tt LOAD}, {\tt RUN}, {\tt EXECUTE}, etc.)
\outlinetwo $\Rightarrow$:
To stop a PASCAL (or any other) program while it is executing:
\outlinetwo :
\undertext{\tt CTRL/C}
\outlinetwo $\Rightarrow$:
To restart it where it left off:
\outlinetwo :
@\undertext{\tt CONTINUE $\return$}
\outlineone $\bullet$:
Handling files.
\outlinetwo $\Rightarrow$:
To copy filesa, calling the copy fileb:
\outlinetwo :
@\undertext{\tt COPY $\esc$ filesa $\esc$ fileb $\return$}
\outlinetwo $\Rightarrow$:
To append filesa \ to fileb \ (useable only for files without line numbers):
\outlinetwo :
@\undertext{\tt APPEND $\esc$ filesa $\esc$ fileb \ $\return$}
\outlinetwo $\Rightarrow$:
To delete files from directory:
\outlinethree :
(Use this cautiously!)
\outlinetwo :
@\undertext{\tt DELETE $\esc$ files $\return$}
\outlinetwo $\Rightarrow$:
To try to restore erroneously deleted files:
\outlinetwo :
@\undertext{\tt UNDELETE $\esc$ {\sl files\/} $\return$}
\vfill\eject
\outlinetwo $\Rightarrow$:
To erase deleted files:
\outlinetwo :
@\undertext{\tt EXPUNGE $\return$}
\outlinetwo $\Rightarrow$:
To compare two files (see @\undertext{\tt HELP SRCCOM $\return$})
\outlinetwo :
@\undertext{\tt SRCCOM $\return$}
\outlineone $\bullet$:
Using other directories.
\outlinetwo $\Rightarrow$:
To work primarily in a particular directory (see
@\undertext{\tt HELP $\esc$ CONNECT $\return$})
\outlinetwo :
@\undertext{\tt CONNECT $\esc$ {\sl directory-name\/} $\return$}
\outlinetwo $\Rightarrow$:
To authorize yourself to use a particular directory (see LOTS Overview
Section 13.6):
\outlinetwo :
@\undertext{\tt ACCESS $\esc$ {\sl directory-name\/} $\return$}
\outlineone $\bullet$:
To get some TOPS-20 commands automatically executed when you log
in and log out, put them into files named, respectively, {\tt LOGIN.CMD} and
{\tt LOGOUT.CMD}. Obvious candidates for automatic commands on login are
{\tt DIRECTORY}, {\tt DAYTIME}, {\tt TYPE MAIL.TXT}, {\tt DELETE MAIL.TXT}, and
{\tt SET DEFAULT PRINT}.
\vfill\eject
\noindent
{\bf APPENDIX D.}
Number Representation of DEC System-20 and Relations to Pascal.
\smallskip
\ctrline{by John G. Herriot}
\smallskip
All numbers are stored in 36-bit words. The 36 bits of a word are numbered
from~0 to~35, from left to right, just to identify them.
%\sendindex{Integers}
\smallskip\noindent
{\bf Integers}
Of the 36 bits in a word, bit 0 (the leftmost bit) represents the sign: 0~for
positive and~1 for negative. In a positive number the remaining 35~bits are the
magnitude of the number stored in a binary (base~2) representation. For
example, $21↓{10}$ (the subscript means base~10, i.e., a decimal number) is stored
as $$\eqalign{&000\ 000\ 000\ 000\ 000\ 000\ 000\ 000\ 000\ 000\ 010\ 101\cr
&\uparrow\cr
&sign\ bit\cr}$$
(The digits are conventionally written in groups of three for ease of reading.
This grouping has no significance for the actual binary representation.) To
check this note that
$${21=\underline{0}\times2↑{34}+\cdots+\underline{0}\times2↑{5}+\underline{1}
\null\times2↑{4}+\underline{0}\times2↑{3}+\underline{1}\times2↑{2}+\underline{0}
\null\times2↑{1}+\underline{1}\times2↑{0}}.$$
The largest positive integer which can be stored in a word is
$$2↑{34}+2↑{33}+\cdots+2↑{1}+2↑{0}=2↑{35}-1=34359738367↓{10}.$$ Any attempt to
create or store an integer larger than $2↑{35}-1$ will produce erroneous
results and the user will not always be warned of the error. Zero is
represented by a word containing all~0s.
To save space in writing words on paper, each group of 3~bits is frequently
converted to a single base-8 (octal) digit, according to the following code:
$$\vcenter{\halign{\ctr{#}&\qquad\ctr{#}&\qquad\ctr{#}&\qquad\ctr{#}\cr
{\undertext{base 2}}&{\undertext{base 8}}&{\undertext{base 2}}%
&{\undertext{base 8}}\cr
000&0&100&4\cr
001&1&101&5\cr
010&2&110&6\cr
011&3&111&7\cr}}$$
However, integers are actually stored as base-2 numbers.
Using octal notation, the decimal number 21 is represented by $000000000025↓8$.
Note that $25↓8$ is the octal representation of $21↓{10}$.
Negative numbers have a sign bit of 1 and are stored in what is called ``two's
complement form''. First we define the {\sl one's complement\/} of a number in
binary form as the result obtained by changing every 0 to 1 and every 1 to 0.
The {\sl two's complement\/} of a number in binary form is obtained by taking the
one's complement of the portion of the number to the left of the lowest order~1
and leaving the rest of the number unchanged. Notice that taking the two's
complement of the two's complement of a number restores the original number.
For example, $-1$ is stored as
$$111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111$$
which may be written as $777777777777↓8$. Also, $-21$ is stored as
$$111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 111\ 101\ 011$$
To check this, note one can take the two's complement of this number, obtaining
the representation for +21 which can be evaluated as previously explained.
Alternatively one can regard the value of the sign bit as $-2↑{35}$ and give
the other digits their conventional values. Thus
$$-2↑{35}+\underline{1}\times2↑{34}+\cdots+\underline{1}\times2↑5+\underline{0}
\times2↑4+\underline{1}\times2↑3+\underline{0}\times2↑2+\underline{1}\times
2↑1+\underline{1}\times2↑0=-21\,.$$
The smallest integer which can be stored in the DEC System-20 is
$$-2↑{35}=-34359738368↓{10}$$
and it is represented by $400000000000↓8$. Note
that it cannot be produced by negating any positive number and that its
magnitude is one greater than the largest positive number. Remembering that
zero is represented by all~0's, we see that taking the negative of this number
means that no change is made because there is no digit~1. Thus there is only
one zero representation and its sign is positive.
Another way to think of the representation of negative numbers is to consider
a 36-place binary accumulating register (the base-2 equivalent of the decimal
accumulating register in a small mechanical calculator).
If one starts with all zeros
in their register, one gets the representation for $-1$ by subtracting~1. The
process requires a ``borrow'' to propagate to the left all the way across
the register, leaving all ones, just as on a decimal calculator this would
leave all nines. Continued subtractions will give the representations for
$-2,-3,\ldots$.
%\sendindex{Real Numbers}
\medskip\noindent
{\bf Real Numbers}
Numbers in many scientific computations will grow in magnitude well beyond
the range of integers described above. To provide for this, DEC System-20
and most scientific computers have a second way to represent numbers ---
the so-called {\sl floating-point representation\/}. The significance
of the name ``floating-point'' is that the {\sl radix point\/}---for example,
the decimal point in base-10 numbers---is permitted to float to the right
or left, thus permitting scaling of numbers by various powers of the radix.
Although a decimal point that has floated off to the left will produce a number
written like 0.001345, the numbers are actually represented in a form closer
to what is often called {\sl scientific notation\/}, here $.1345\times 10↑{-2}$.
In DEC System-20 floating-point numbers are represented in base-2 notation, i.e.,
the radix or number base is~2. As in the case of integers, bit~0 (the leftmost
bit) represents the sign, 0~for positive and~1 for negative. The remaining
35~bits represent an 8-digit exponent and a 27-bit fraction. Bits~9 to~35 are
interpreted as a binary fraction, i.e., 27~binary digits with a binary point
at the left-hand end. This part is called the {\sl mantissa\/}.
Bits~1 to~8 are interpreted as an integral exponent in excess $128 (200↓8)$ code.
This means that bits 1--8 may be thought of as giving the binary (base-2)
representation of a nonnegative integer in the range $0↓{10}$ to $255↓{10}$,
inclusive. This integer is called the {\sl biased exponent\/} for reasons now to
be explained. If this integer were taken directly as the exponent, we would have
no negative exponents, and our range of floating-point numbers could not include
such numbers as $2↑{-100}$. It is desirable to have an exponent range which is
approximately symmetric about zero. One obtains the {\sl true exponent\/} of the
floating-point number by subtracting~128 from the biased exponent represented by
bits~1 to~8; this explains the name, excess 128~code. As a result, the true
exponents range from ${-128}$ to~127.
As noted above, the 27 bits 9 to 35 are regarded as a binary fraction with a
binary point at the left-hand end. If the floating number zero is being
represented all the bits are~0. Otherwise, at least one of the binary digits
must be nonzero. A floating-point number is said to be {\sl normalized\/}
if the left-hand binary digit (the most significant digit), bit~9, is~1. In
DEC System-20 the floating-point numbers are ordinarily normalized and we shall
not consider any other forms. Hence, the mantissa,~$M$, may be positive or
negative and its magnitude lies in the range $1/2 ≤ \left| M\right| < 1$.
Negative floating-point numbers are stored in two's complement form. Thus a
negative number has a~1 for its sign and the two's complement of the remaining
bits. Since every fraction (except zero) ordinarily contains a~1, it has the
one's complement of the exponent code in bits~1 to~8.
We now give the floating-point representation of some sample numbers. As we
said before, the number zero is represented by 36~zero bits. Thus zero is
represented by the same word in floating-point or integer form. No other
number has this property. The number~1.0 is represented by the word
$$\vbox{\halign{#\hfill&\qquad\hfill#\hfill&\qquad\hfil#\hfil\cr
0&10 000 001&100 000 000 000 000 000 000 000 000\cr
$\uparrow$\cr%&&$\upbracefill$&&$\upbracefill$\cr
sign&biased&mantissa\qquad\qquad\cr
bit&exponent\cr
}}$$
\noindent
To check this, note the sign is 0 (representing $+$). The biased exponent is
$10000001↓2$ or $129↓{10}$. Subtracting $128↓{10}$ yields~1 as the true
exponent. Putting a binary point at the left of the mantissa gives the
binary fraction whose value is $1\over2$. (This binary fraction could be
written more concisely in octal form as $.400000000↓8$.) Thus the above
word represents $+(1/2)\times2=1.0$. To save writing, the above word may be
written in octal form $201400000000↓8$. The number $-1.0$ is represented by the
word
$$\vbox{\halign{#\hfil&\qquad\hfil #\hfil&\qquad\hfil #\hfil\cr
1&01 111 110&100 000 000 000 000 000 000 000 000\cr
$\uparrow$\cr%&$\upbracefill$&$\upbracefill$\cr
sign&biased&mantissa\qquad\qquad\cr
bit&exponent&(2's complement)\qquad\qquad\cr
&(1's complement)\cr
}}$$
\noindent
To check this, note that the sign is 1 (representing $-$). The biased exponent
(after taking one's complement) is $10000001=129↓{10}$ and the true exponent
is~1. Taking the two's complement of the mantissa we see that it is unchanged
(in this example) and its value is $1/2$. Thus the above word represents
$-({1\over2})\times2=-1.0$. It may be written in octal form $576400000000↓8$.
Several examples of floating-point numbers are now given in octal notation,
with the confirmation left to the reader.
\vfill\eject
$$\halign{\hfill#\hfill&\qquad${#}$\qquad\hfill\cr
\undertext{decimal}&&&\undertext{floating-point}\ (octal notation)\cr
0.0&&=&000000000000\cr
1.0&&=&201400000000\cr
$-$1.0&&=&576400000000\cr
23.0&&=&205560000000\cr
$-$23.0&&=&572220000000\cr
0.0&625&=&175400000000\cr
$-$0.0&625&=&602400000000\cr
16.0&&=&205400000000\cr
$-$16.0&&=&572400000000\cr
256.0&&=&211400000000\cr
$-$256.0&&=&566400000000\cr
3.5&&=&202700000000\cr
$-$3.5&&=&575100000000\cr
153.0&&=&210462000000\cr
$-$153.0&&=&567316000000\cr}$$
Notice that in checking the negative numbers one can take the two's complement
of the number in octal notation directly in the following way:
\outlineone $\bullet$:
take the 7's complement of all digits to the left of the lowest
order non-zero digit (i.e., subtract each digit from~7)
\outlineone $\bullet$:
take the 8's complement of the lowest order non-zero digit.
\vskip 22pt
The largest floating-point number is
$377777777777↓8$ representing $2↑{127}\times(1-2↑{-27})=.170\times10↑{39}$.
The smallest positive floating-point number is $000400000000↓8$, representing
$2↑{-129}=.14693\times10↑{-38}$.
The negatives of these
two numbers are the extremes in magnitude of representable negative numbers.
They are represented by $400000000001↓8$ and $777400000000↓8$ respectively.
Since~$2↑{-27}$ is approximately equal to~$10↑{-8}$, the precision of a~27
bit binary number is approximately~$10↑{-8}$. Thus 27~binary bits are roughly
equivalent to 8~decimal digits. For Pascal at LOTS the default condition for
a {\tt WRITE} or {\tt WRITELN}
command causes real numbers to be printed out in the form
${\tt\spa\spa\spa}x.xxxxxxE{\pm}yy$.
That is, there are 6~digits to the right of the
decimal point and one digit to the left of the decimal point. Here
$yy$~denotes the power of~10 which multiplies the printed mantissa.
Very few numbers can be represented exactly with 8~decimal digits. For
example, $1/80=.012500000↓{10}$ is exactly represented,
but $1/3=.33333333↓{10}$
only approximately. In the same way very few numbers can be exactly
represented with 27~binary digits (9 octal digits). For example,
$1/8=.100000000↓8$ is exactly represented, but $1/3 = .252525253↓8$
only approximately. Moreover, some numbers that are
exactly representable in decimal are only approximately representable in binary;
for example, $1/10=.10000000↓{10}$ exactly but $1/10=.063146315↓8$
only approximately.
Conversely, some numbers that are exactly representable by 27~binary digits
are only approximately representable by 8~decimal digits.
For example, the floating-point number closest to~1.0 and above~1.0 has
a mantissa
$$M=.400000001↓8$$
and an exponent~1. Its value is
$$1+2↑{-26}=1.000\ 000\ 014\ 901\ 161\ 193\ 847\ 656\ 25↓{10}$$
The default write command in Pascal produces ?????. But by using the
format parameter to cause this number to be printed with 26~digits to the
right of the decimal point, the exact value given above is obtained. The
floating-point number closest to~1.0 and below~1.0 has a mantissa
$$m=.7777777777↓8$$
and an exponent 0. Its value is
$$1-2↑{-27}=0.999\ 999\ 992\ 549\ 419\ 403\ 076\ 171\ 875.$$
The default write command in Pascal produces ?????. But by using
the format parameter to cause this number to be printed with 26~digits to the
right of the decimal point, the value
$$0.999\ 999\ 988\ 079\ 071\ 044\ 921\ 875\ 00$$
is obtained. This result agrees with the true value in its first 7~digits
only.
Thus round-off enters into the representation of most floating-point numbers
on DEC System-20 and the round-off differs from that with decimal numbers. This
can easily give rise to unexpected results.
It is of interest to note that $.700000000↓{10}$, when printed by the default
{\tt WRITE} command appears as ????? showing that conversion to binary
form and reconversion to decimal form for printing introduces some errors.
Because of round-off error, it is dangerous to compare reals in Pascal for
equality. For example, if
$$product := 700.0\;\ast\;0.700$$
the boolean expression
$$product = 490$$
would be FALSE.
%\sendindex{Pascal Arithmetic}
\vfill\eject
\noindent
{\bf Pascal Arithmetic}
When doing arithmetic with integers in Pascal, the operations, $+$, $-$,
$\ast$, either
give exact integer results, or else result in integers too long to store in
35~bits (overflow) and cause an error halt. The division operation, {\tt DIV},
and the remainder operation, {\tt MOD}, can only be applied to integer operands and
they give exact integer results. When the division operation, $/$, is applied
to integers in Pascal, the integers are first converted to real floating-point
numbers and the resulting quotient is real.
When arithmetic is done with real numbers in PASCAL, the exact result may
not be representable by 27~binary bits. If the result is too large
(overflow) or too small (underflow) an error halt occurs with a message
\smallskip\halign{\lft{\tt #}\cr
ARITHMETIC OVERFLOW OR ZERODIVIDE.\cr}
\smallskip\noindent
%\sendnotes{==>RWF - Is this always true-check out}
If it cannot be represented exactly,
it is rounded to 27~bits (in normalized form) giving the closest
representable number. If the true result is~$X$, then the calculated
result is always between \hfil\break
$X(1-2↑{-27})$ and $X(1+2↑{-27})$. Naturally the
accumulation of these small errors throughout the steps of the program may
give rise to large errors in the final result.
An integer value may be assigned to a real variable but a real value
cannot be assigned to an integer variable. If {\tt X} is a real value, one
may assign {\tt ROUND(X)} or {\tt TRUNC(X)} to an integer variable provided this
integer value does not exceed the maximum allowable integer value.
When an integer value, {\tt N}, is assigned to a real variable, if the
integer requires more than 27~bits of precision $(2↑{27}=134217728)$,
then some low order significance will be lost in the conversion to real;
otherwise, conversion to real and then back to integer using the
{\tt ROUND} or {\tt TRUNC} functions will result in the same integer value.
This means
that if an integer value is less than~$2↑{27}$ it will be represented
exactly as a floating-point number. But even if the integer value
exceeds~$2↑{27}$,
it would be represented exactly if in its binary representation,
the leftmost and rightmost~1's are not more than 26~positions apart.
When the two operands of a Pascal operation, $+$, $-$, $\ast$, $/$ are of
different type, the integer operand is converted first to real type
so that the arithmetic is done with real numbers.
\vfill\eject
\noindent
{\bf APPENDIX E.}
Finding the Root of an Equation.
For what value of $x$ is $\cos(x) = x$? I.e.,
$\cos(x) - x = 0$.
$\cos(0)-0$ is $1 > 0$. $\cos(\pi/2) - \pi/2$ is $-{\pi/2}< 0$.
Somewhere between,
$\cos(x)-x = 0$. We plan to narrow down the range in which the desired $x$ lies,
by a factor of two at every step. Given two numbers $lo$ and $hi$, where we
know that $lo ≤ x$ (so $\cos(lo) - lo ≥ 0$) and $hi ≥ x$ (so
$\cos(hi) - hi ≤ 0$), we take a number between them, $mid = (hi + lo)/2$,
and depending on whether $\cos(mid) - mid ≥ 0$ or $< 0$, we take $mid$ as
the new value of $hi$ or $lo$. We continue this until $hi - lo$ is very small;
$x$~always lies between them.
\smallskip\halign{\qquad\lft{\tt #}\cr
BEGIN\cr
REAL LO, MID, HI;\cr
LO := 0;\cr
HI := 3.1416/2;\cr
WHILE HI-LO > 0.000001 DO\cr
\qq BEGIN\cr
\qq (* LO <= X <= HI, F(LO) >= 0, F(HI) <= 0 *)\cr
\qq MID := (HI+LO)/2;\cr
\qq IF COS(MID)-MID >= 0 THEN\cr
\qq\qq LO := MID\cr
\qq ELSE HI := MID\cr
\qq (* HI-LO HAS DECREASED BY HALF *)\cr
\qq END;\cr
WRITELN(`X SUCH THAT COS(X) = X IS', (HI+LO)/2)\cr
END\cr}
\smallskip
The key to the above program is the invariant of the iteration: every time
we go through it, we start with a number in $lo$ which is less than the
desired~$x$, and a number in $hi$ which is larger. Knowing this, it is easy
to find a new value for one or the other which is still on the correct side
of~$x$, but is closer.
In order to know that the program will terminate, we have to see that
eventually, the difference between $hi$ and $lo$ will get less than any
positive number. (Actually, because of rounding errors, the difference may
only get down to about $10↑{-8}$ and just stay there; this is why the test
for termination was based on a number larger than $10↑{-8}$.) It is very
important, when designing indefinite iterations, to be sure that they
won't go on forever.
\vfill\eject
\noindent
{\bf APPENDIX F.}
Numerical Calculus.
In pure mathematics, when you have determined the sum of an infinite
series, you've said it all:
$$\sum↑\infty↓{i=1}{1\over{i↑2}} = {\pi↑2\over6},$$ say.
If you want to find a good approximate value for
$\pi↑2/6$ from this series, perhaps by evaluating
$$\sum↑n↓{i=1}{1\over{i↑2}}$$ for some large {\tt n}, you find that the error
is large unless {\tt n} is very large. The error is
$$\sum↑\infty↓{i=n+1}{1\over i↑2}\approx{\int↑\infty↓n}{x↑{-2}dx} = {1\over{n}}.$$
To get six-place accuracy, we need to
have $n$ around $2\times10↑6$. But then, we find that the accumulated
rounding errors of about $10↑{-8}$ per addition (on the DEC System 20)
have left our results wrong by about
%\sendnotes{DPB->RWF: check forumulae}
$(2\times10↑6)\times10↑{-8}=2\times10↑{-2}$,
so we are
very far off. To use computers to calculate numbers defined by limits,
we have to not only to approach the limits, but approach them fast enough
that we can get the result in reasonable time, without accumulating too
many small errors along the way.
The analysis above shows that
$$\sum↑n↓{i=1}{1\over{i↑2}}\approx S+{a\over n},\quad (\approx \hbox{\rm means ``is close to''})$$
where $S = {\pi{↑2}/6}$ and $a$ is some constant. A more careful analysis
would show that
$$\sum↑n↓{i=1}{1\over{i↑2}}\approx S+{a\over n}+{b\over{n↑2}}+{c\over n↑3}+\cdots;$$
that is, the error in using the finite sum is a convergent series of powers of
$1/n$ in which all terms go to zero as $n$ gets large. If we could get
rid of the term $a/n$, we would have a much smaller error for large $n$.
Define
$$S↓0(n) = \sum↑n↓{i=1}{1\over{i↑2}} = S + {a\over n} + {b\over{n↑2}} +
{c\over{n↑3}} + \cdots\;.$$
Then $S↓0(2n)$, summing twice as many terms, is
$$S + {a\over{2n}} + {b\over{4n↑2}} + {c\over{8n↑3}} + \cdots\;.$$
Eliminating $a$ between $S↓0(n)$ and $S↓0(2n)$, we define
$$S↓1(n) = 2S↓0(2n) - S↓0(n) = S - {1\over2}{b\over{n↑2}} - {3\over4}{c\over{n↑3}} - \cdots\;.$$
so $S↓1(n)$ approaches $s$ much faster than $S↓0(n)$ does.
Now
$$S↓1(2n) = S - {1\over8}{b\over{n↑2}} - {3\over{32}}{c\over{n↑3}} - \cdots\;,$$
and we can elminate $b$ between
$S↓1(n)$ and $S↓1(2n)$:
$$S↓2(n) = {4S↓1(2n) - S↓1(n)\over3} = S + \hbox{terms in}\ {1/n↑4}.$$
Another step gives:
$$S↓3(n) = {{8S↓2(2n) - {S↓2(n)}\over7}} = S + \hbox{terms in}\ {1/n↑6}$$
%\sendnotes{DPB->RWF: check "terms in" in both places.}
Using $n = 4$, we get, using a pocket calculator for ten minutes,
$$\vcenter{%
%\halign{$\ctr{#}$\quad&$\ctr{#}$\quad&$\ctr{#}$\quad&$\ctr{#}$\cr
\halign{$\rt{#}\;$&$\lft{#}$\quad
&$\rt{#}\;$&$\lft{#}$\quad
&$\rt{#}\;$&$\lft{#}$\quad
&$\rt{#}\;$&$\lft{#}$\cr
S↓0(n)&= 1.4236111&S↓1(n)&= 1.6312732&S↓2(n)&= 1.6446036&S↓3(n)&= 1.6449350\cr
S↓0(2n)&= 1.5274221&S↓1(2n)&= 1.6412710&S↓2(2n)&= 1.6448936\cr
S↓0(4n)&= 1.5843465&S↓1(4n)&= 1.6439880\cr
S↓0(8n)&= 1.6141672\cr}}$$
where $S↓3(n) - {\pi↑2/6} = .0000009$, as small an error as if we had
evaluated
$$\sum↑{10↑6}↓{i=1}{1\over i↑2}$$
using twelve- or thirteen-digit numbers.
This is not necessarily the best way to evaluate $\pi↑2/6$, and it
works very badly on some other infinite series so it should not be used
generally; it shows, however, that calculus with actual numbers involves
an ingredient not present in the pure calculus: finding ways to achieve
very high precision with very little computation.
\medskip\noindent{\bf Exercise}
Program the analogous computation of $\ln(2)$
$$\eqalign{\ln(2)&= 1-{1\over2}+{1\over3}-{1\over4}+{1\over5}-{1\over6}\ldots\cr
\noalign{\smallskip}
&={1\over2}+{1\over{12}}+{1\over{20}}+\cdots+{1\over{(2i-1)2i}}+\ldots\cr}$$
with
$$S↓0(n) = \sum↑n↓{i=1}{1\over{(2i-1)2i}}$$
up to $S↓4(5)$. Print out each $S↓{j}(5)$, and its difference from $\ln(2)$.
\vskip 11pt
We could calculate an integral in a similar way. We can approximate
$$I = {\int↑1↓0}f(x)\,dx$$
by
$$I↓0(n) = {1\over n}\sum↑{n-1}↓{i=0}f\left({i+{1\over2}}\over n\right).$$
$$I↓0(n) = I + {a\over{n↑2}} + {b\over{n↑4}} + {c\over{n↑6}} + \cdots$$
See if you can work out an analogous method for computing the integral
accurately without too many evaluations of $f$. (Idea: try eliminating $a$ between
$I↓0(n)$ and $I↓0(3n)$. Notice that the sum in
$I↓0(n)$ is a part of the sum in $I↓0(3n)$.) Try it out on
$${\int↑1↓0}{e↑{-x↑2/2}\,dx} = 0.3413\ldots$$
\vfill
\bigskip
\parindent0pt
\copyright 1984 Robert W. Floyd
First draft 1982 (?)
\end